package com.autonavi.yunda.yunji.core.model.condition;

import com.autonavi.yunda.yunji.core.model.dto.OperationRecordDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;

/**
 * @author sunzhenbang
 */
@Data
public class OperationQueryCondition {
    private String type;
    private String subType;
    private String operatorId;
    private String operatorName;
    private String relatedId;
    @NotNull
    public Integer pageNo;
    @NotNull
    public Integer pageSize;

    public QueryWrapper<OperationRecordDTO> getFunctionWrapper(OperationQueryCondition condition) {
        QueryWrapper<OperationRecordDTO> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        if (StringUtils.isNotBlank(condition.getType())) {
            wrapper.like("type", String.join("%", condition.getType(), "%"));
        }
        if (StringUtils.isNotBlank(condition.getSubType())) {
            wrapper.like("sub_type", String.join("%", condition.getSubType(), "%"));
        }
        if (StringUtils.isNotBlank(condition.getOperatorId())) {
            wrapper.like("operator_id", String.join("%", condition.getOperatorId(), "%"));
        }
        if (StringUtils.isNotBlank(condition.getOperatorName())) {
            wrapper.like("operator_name", String.join("%", condition.getOperatorName(), "%"));
        }
        if (StringUtils.isNotBlank(condition.getRelatedId())) {
            wrapper.like("related_id", String.join("%", condition.getRelatedId(), "%"));
        }
        return wrapper;
    }
}

